package com.member.web.controller.shop;

import com.member.shop.domain.SysBizUserSign;
import com.member.shop.domain.SysBizUserSurplusDetails;
import com.member.shop.service.ISysBizUserSignService;
import com.member.common.annotation.Log;
import com.member.common.core.controller.BaseController;
import com.member.common.core.domain.AjaxResult;
import com.member.common.core.page.TableDataInfo;
import com.member.common.enums.BusinessType;
import com.member.common.utils.poi.ExcelUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 会员签到Controller
 *
 * @author thomas
 * @date 2024-05-18
 */
@RestController
@RequestMapping("/shop/user/sign")
public class SysBizUserSignController extends BaseController {
    @Resource
    private ISysBizUserSignService sysBizUserSignService;

    /**
     * 查询会员签到列表
     */
    @PreAuthorize("@ss.hasPermi('user:sign:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysBizUserSign sysBizUserSign) {
        startPage();
        setTenantId(sysBizUserSign);
        List<SysBizUserSign> list = sysBizUserSignService.selectSysBizUserSignList(sysBizUserSign);
        return getDataTable(list);
    }
    private void setTenantId(SysBizUserSign sysBizUserSign) {
        Long tenantId = getTenantId();
        if (tenantId != null && tenantId > 0) {
            sysBizUserSign.setTenantId(tenantId);
        }
    }
    /**
     * 导出会员签到列表
     */
    @PreAuthorize("@ss.hasPermi('user:sign:export')")
    @Log(title = "会员签到", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysBizUserSign sysBizUserSign) {
        setTenantId(sysBizUserSign);
        List<SysBizUserSign> list = sysBizUserSignService.selectSysBizUserSignList(sysBizUserSign);
        ExcelUtil<SysBizUserSign> util = new ExcelUtil<SysBizUserSign>(SysBizUserSign.class);
        util.exportExcel(response, list, "会员签到数据");
    }

    /**
     * 获取会员签到详细信息
     */
    @PreAuthorize("@ss.hasPermi('user:sign:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(sysBizUserSignService.selectSysBizUserSignById(id));
    }

    /**
     * 新增会员签到
     */
    @PreAuthorize("@ss.hasPermi('user:sign:add')")
    @Log(title = "会员签到", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysBizUserSign sysBizUserSign) {
        return toAjax(sysBizUserSignService.insertSysBizUserSign(sysBizUserSign));
    }

    /**
     * 修改会员签到
     */
    @PreAuthorize("@ss.hasPermi('user:sign:edit')")
    @Log(title = "会员签到", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysBizUserSign sysBizUserSign) {
        return toAjax(sysBizUserSignService.updateSysBizUserSign(sysBizUserSign));
    }

    /**
     * 删除会员签到
     */
    @PreAuthorize("@ss.hasPermi('user:sign:remove')")
    @Log(title = "会员签到", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(sysBizUserSignService.deleteSysBizUserSignByIds(ids));
    }
}
